package com.lqq.controller.restfull;

import com.lqq.consumer.Consumer;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.rocketmq.client.exception.MQClientException;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.net.InetAddress;
import java.net.UnknownHostException;

/**
 * @author lqq
 * @date 2019/1/6
 */
@RestController
@Api(description = "index")
public class IndexController {


    @RequestMapping({"", "/" , "/index"})
    @ApiOperation(value = "index",httpMethod = "GET")
    public String index() throws UnknownHostException {
        InetAddress address = InetAddress.getLocalHost();
        return  "indexMethod: 当前主机ip地址信息：" + address.getHostAddress();
    }

    @RequestMapping({"/hello"})
    @ApiOperation(value = "启动消费者",httpMethod = "GET")
    public String hello() throws UnknownHostException {
        InetAddress address = InetAddress.getLocalHost();

        Consumer consumer = new Consumer();
        try {
            consumer.init();
        } catch (Exception e) {
            throw new  RuntimeException("初始化异常" ,e);
        }

        return  "消费者已经启动";
    }
}
